package com.molyfun.parents.activity.schoolonline.homework.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.molyfun.parents.R;
import com.molyfun.parents.view.common.MfEditText;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/18/16.
 *
 * 科大讯飞语音转文字在这里
 */
public class VoiceInputView extends LinearLayout implements View.OnClickListener{

    protected LayoutInflater layoutInflater;

    private Context context;

    @InjectView(R.id.voice_input_edt)
    MfEditText mInputEdt;
    @InjectView(R.id.voice_input_btn)
    ImageView mInputBtn;


    public VoiceInputView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public VoiceInputView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public VoiceInputView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_voice_input, this);
        ButterKnife.inject(this);
        mInputBtn.setOnClickListener(this);
    }

    public String getInputText(){
        return mInputEdt.getText().toString().trim();
    }

    public void setInputText(String str){
        if(!TextUtils.isEmpty(str)){
            mInputEdt.setText(mInputEdt.getText().toString() + str);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.voice_input_btn:
                if(mOnVoiceInputCallback != null){
                   mOnVoiceInputCallback.onVoiceInput();
                }
                break;
        }
    }

    public void setOnVoiceInputCallback(OnVoiceInputCallback onVoiceInputCallback) {
        this.mOnVoiceInputCallback = onVoiceInputCallback;
    }

    private OnVoiceInputCallback mOnVoiceInputCallback;

    public interface OnVoiceInputCallback{
        public void onVoiceInput();
    }

}